package homework12月8号.homework1.h9;

import org.apache.commons.io.FileUtils;

import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/*7.	IO+空参构造+调用get/set方法
现有Cat类和CatData.txt 文件(自行完善包名)，读取文件中的内容，使用反射创建Cat对象和为属性赋值

CatData.txt 文件内容如下：
包名.Cat name=’星星’ age=3


public class Cat {

    private String name;

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
*/
public class Demo1 {
    public static void main(String[] args) throws IOException, Exception {
        List<String> list = FileUtils.readLines(new File("D:\\ldea dashuju\\day.12.6\\src\\czxy\\homework\\h9\\CatData.txt"));
        ArrayList<Cat> cats = new ArrayList<>();
        for (String s : list) {
            String[] s1 = s.split(" ");
            System.out.println(Arrays.toString(s1));
            Class<?> aClass = Class.forName(s1[0]);
            Cat cat = (Cat) aClass.newInstance();
            String[] split = s1[1].split("\\'");
            cat.setName(split[1]);
            String[] split1 = s1[2].split("=");
            cat.setAge(Integer.parseInt(split1[1]));
            cats.add(cat);
        }
        System.out.println(cats);
    }
}
